<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>
            用户管理-修改密码
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="${ctxPath}/static/manage/css/x-admin.css" media="all">
        <script src="${ctxPath}/static/manage/layui/layui.js" charset="utf-8"></script>
        <script src="${ctxPath}/static/manage/js/x-layui.js" charset="utf-8"></script>
    </head>
    <body>
        <div class="x-nav">
            <span class="nav-breadcrumb">
                <a><cite>后台管理></cite></a>
                <a><cite>个人中心></cite></a>
                <a><cite>修改密码</cite></a>
             </span>
        </div>
        <div class="x-body">
            <form class="layui-form" id="formUpdate" >
                <input type="hidden" id="id" name="id" value="${currentUser.id}" class="layui-input">
                <input type="hidden" id="oriPassword" value="${currentUser.password}" class="layui-input">
                <div class="layui-form-item">
                    <label class="layui-form-label">昵称</label>
                    <div class="layui-input-inline">
                        <input type="text" disabled="" value="${currentUser.name}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="oldPassword" class="layui-form-label">
                        <span class="x-red">*</span>旧密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="oldPassword" required lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="newPassword" class="layui-form-label">
                        <span class="x-red">*</span>新密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="newPassword" name="newPassword" required lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span class="x-red">*</span>必填 6到16个字符</div>
                </div>
                <div class="layui-form-item">
                    <label for="rePassword" class="layui-form-label">
                        <span class="x-red">*</span>确认密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="rePassword" required lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux"><span class="x-red">*</span>必填 6到16个字符</div>
                </div>
                <div class="layui-form-item">
                    <label for="rePassword" class="layui-form-label"></label>
                    <button class="layui-btn" type="button" lay-filter="update" lay-submit>确定修改</button>
                </div>
            </form>
        </div>
    </body>
    <script type="text/javascript">
        layui.use(['form','layer'], function(){
            var $ = layui.$, form = layui.form;

            //监听提交
            form.on('submit(update)', function(){
                var oriPassword = $("#oriPassword").val();
                var oldPassword = $("#oldPassword").val();
                var newPassword = $("#newPassword").val();
                var rePassword = $("#rePassword").val();

                // 判断输入的旧密码和原密码是否一致；俩次新密码一致；密码不能为空
                if(oldPassword != oriPassword){
                    alert("输入的旧密码不正确，请重新输入");
                    return false;
                }
                if(rePassword != newPassword){
                    alert("两次密码不一致");
                    return false;
                }
                if(newPassword.length<=0){
                    alert("新密码不能为空");
                    return false;
                }
                $.ajax({
                    url:'/manage/user/updatePassword',
                    type:'post',
                    data:$("#formUpdate").serialize(),
                    success:function(result){
                        alert(result);
                        window.parent.location.href = "/logout";
                    }
                });
                return false;
            });

        });
    </script>

</html>